home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep2 / MemMon 2.0 / Samples / concord_strings.icn < prev    next >
Encoding:
Text File  |  1990-07-18  |  1014 b   |  59 lines  |  [TEXT/PICN]

  1. #  Concordance program using strings
  2.  
  3. global uses, lineno, width
  4.  
  5. procedure main(args)
  6.    local word, line
  7.  
  8.    width := 15                # width of word field
  9.    uses := table("")
  10.    lineno := 0
  11.  
  12.    every tabulate(words())        # tabulate all the citations
  13.  
  14.    output()                # print the citations
  15.  
  16. end
  17.  
  18. #  Add line number to citations for word
  19. #
  20. procedure tabulate(word)
  21.  
  22.    if uses[word][-2 -: *lineno] == lineno then return
  23.    else {
  24.       uses[word] ||:= lineno || ", "    # new line number
  25.       return
  26.       }
  27.  
  28. end
  29.  
  30. #  Generate words
  31. #
  32. procedure words()
  33.    local s, line
  34.  
  35.    while line := read() do {
  36.       lineno +:= 1
  37.       write(right(lineno,6),"  ",line)
  38.       map(line) ? while tab(upto(&letters)) do {
  39.          s := tab(many(&letters))
  40.          if *s < 3 then next            # skip short words
  41.          suspend s
  42.          }
  43.       }
  44.  
  45. end
  46.  
  47. #  Print the results
  48. #
  49. procedure output()
  50.    local word
  51.  
  52.    write()
  53.  
  54.    uses := sort(uses,3)            # sort citations
  55.    while word := get(uses) do
  56.       write(left(word,width),get(uses)[1:-2])
  57.  
  58. end
  59.